//
//  CXLNetworkTool.m
//  WYNews
//
//  Created by 夜猫子 on 2017/3/19.
//  Copyright © 2017年 夜猫子. All rights reserved.
//

#import "CXLNetworkTool.h"

@implementation CXLNetworkTool

/**
 单例
 
 */
+ (instancetype)sharedTool{
    
    static CXLNetworkTool *tool = nil;
    static dispatch_once_t onceToken;
    dispatch_once(&onceToken, ^{
        tool = [[CXLNetworkTool alloc] init];
        
    });
    return tool;
}

/**
 网络中间层调用方法
 
 */
- (void)reqeustWith:(NSString *)url method:(NSString *)method parameters:(NSDictionary *)parameters callBlock:(void(^)(id response))callBlock{
    
    if ([method isEqualToString:@"GET"]) {
        
        [self GET:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            callBlock(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            callBlock(nil);
        }];
        
    }
    if ([method isEqualToString:@"POST"]) {
        
        [self POST:url parameters:parameters progress:nil success:^(NSURLSessionDataTask * _Nonnull task, id  _Nullable responseObject) {
            
            callBlock(responseObject);
        } failure:^(NSURLSessionDataTask * _Nullable task, NSError * _Nonnull error) {
            
            callBlock(nil);
        }];
        
    }
    
    
    
}

@end
